package com.ztc.ZtcOrderTicket.dao;
import java.util.List;
import org.springframework.stereotype.Repository; 
import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcOrderTicket.bean.ZtcOrderTicket;
/**
 * <p>
 * 
 * </p>
 * 
 * @ClassName ZtcOrderTicketDao
 * @JDK 1.5
 * @author 
 * @date  
 */
@Repository("ZtcOrderTicketDao")
public class ZtcOrderTicketDao extends BaseDaoImpl<ZtcOrderTicket> {
	public String save(ZtcOrderTicket ztcOrderTicket) {
		this.getHibernateTemplate().save(ztcOrderTicket);
		return ztcOrderTicket.getId();
	}

	public List<ZtcOrderTicket> getAllZtcOrderTickets() {
		return this.getAll();
	}

	public String delete(ZtcOrderTicket ztcOrderTicket) {
		String sql = "delete from ztc_order_ticket where 1=1";
		if (ztcOrderTicket.getId() != null) {
			sql += " and id='" + ztcOrderTicket.getId() + "'";
		}
		if (ztcOrderTicket.getFkOrderId() != null) {
			sql += " and fk_order_id='" + ztcOrderTicket.getFkOrderId() + "'";
		}
		if (ztcOrderTicket.getPassengerType() != null) {
			sql += " and passenger_type='" + ztcOrderTicket.getPassengerType() + "'";
		}
		if (ztcOrderTicket.getSeatType() != null) {
			sql += " and seat_type='" + ztcOrderTicket.getSeatType() + "'";
		}
		if (ztcOrderTicket.getStatus() != null) {
			sql += " and status='" + ztcOrderTicket.getStatus() + "'";
		}
		if (this.currentSession().createNativeQuery(sql).executeUpdate() >= 0) {
			return "1";
		}
		return "0";
	}

	public List<ZtcOrderTicket> searchInfoEquals(ZtcOrderTicket ztcOrderTicket) {
		String sql = "select * from ztc_order_ticket  where 1=1";
		if (ztcOrderTicket.getPassengerName() != null) {
			sql += " and passenger_name='" + ztcOrderTicket.getPassengerName() + "'";
		}
		if (ztcOrderTicket.getPassengerBirthday() != null) {
			sql += " and passenger_birthday='" + ztcOrderTicket.getPassengerBirthday() + "'";
		}
		if (ztcOrderTicket.getPassengerType()!= null) {
			sql += " and passenger_type='" + ztcOrderTicket.getPassengerType() + "'";
		}
		if (ztcOrderTicket.getPassengerCardNumber() != null) {
			sql += " and passenger_card_number='" + ztcOrderTicket.getPassengerCardNumber() + "'";
		}
		if (ztcOrderTicket.getPassengerCardType() != null) {
			sql += " and passenger_card_type='" + ztcOrderTicket.getPassengerCardType() + "'";
		}
		if (ztcOrderTicket.getSeatNumber()!= null) {
			sql += " and seat_no='" + ztcOrderTicket.getSeatNumber() + "'";
		}
		if (ztcOrderTicket.getPrice() != null) {
			sql += " and price='" + ztcOrderTicket.getPrice() + "'";
		}
		if (ztcOrderTicket.getSeatType() != null) {
			sql += " and seat_type='" + ztcOrderTicket.getSeatType() + "'";
		}
		if (ztcOrderTicket.getStatus() != null) {
			sql += " and status='" + ztcOrderTicket.getStatus() + "'";
		}
		if (ztcOrderTicket.getFkOrderId() != null) {
			sql += " and fk_order_id='" + ztcOrderTicket.getFkOrderId() + "'";
		}
		if (ztcOrderTicket.getId() != null) {
			sql += " and id='" + ztcOrderTicket.getId() + "'";
		}
		List<ZtcOrderTicket> list = this.currentSession().createNativeQuery(sql,ZtcOrderTicket.class).getResultList();
		return list;
	}
	
	public List<ZtcOrderTicket> searchInfoLikes(String passengerName) {
		String sql = "select * from ztc_order_ticket  where 1=1";
		if (passengerName != null) {
			sql += " and passenger_name like'%" + passengerName + "%'";
		}
		List<ZtcOrderTicket> list = this.currentSession().createNativeQuery(sql,ZtcOrderTicket.class).getResultList();
		return list;
	}
	public String update(ZtcOrderTicket ztcOrderTicket){
		ZtcOrderTicket ztcOrderTicketBean = this.findUniqueBy("id", ztcOrderTicket.getId());
		this.save(ztcOrderTicketBean);
		if (ztcOrderTicketBean.getId() != null) {
			return "1";
		}
		return "0";
	}
}